<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<head>
    <title>Title</title>
    <%@include file="../../common.jsp"%>
</head>
<style>
    body{
        font-size: 12px;
    }
    #taskTable tr{
        font-size: 12px;
    }
</style>
<body>
<h2>巡检任务</h2>
<hr>
    <form class="layui-form" action="">
        <div class="layui-form-item">

            <div class="layui-inline">
                <label class="layui-form-label">任务编号:</label>
                <div class="layui-input-inline" style="width: 200px;">
                    <input id="taskId" type="text" name="price_min" autocomplete="off" class="layui-input">
                </div>
                <label class="layui-form-label">线路编号:</label>
                <div class="layui-input-inline" style="width: 200px;">
                    <input id="lineCode" type="text" name="price_min" autocomplete="off" class="layui-input">
                </div>
                <label class="layui-form-label">任务状态:</label>
                <div class="layui-input-inline">
                    <select id="taskStateId">
                        <option value="-1">请选择</option>
                        <option value="1">待分配</option>
                        <option value="2">已分配</option>
                        <option value="3">执行中</option>
                        <option value="4">已完成</option>
                    </select>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">下发人:</label>
                <div class="layui-input-inline">
                    <input id="issuedByName" type="text" name="price_min" autocomplete="off" class="layui-input">
                </div>
                <label class="layui-form-label">下发时间:</label>
                <div class="layui-input-inline">
                    <input type="text" class="layui-input" id="startTime" placeholder="yyyy-MM-dd">
                </div>
                <div class="layui-form-label" style="width:5px">-</div>
                <div class="layui-input-inline">
                    <input type="text" class="layui-input testl" id="endTime" placeholder="yyyy-MM-dd">
                </div>


                <div class="layui-input-inline" style="width: 100px;">
                    <button type="button" class="layui-btn layui-btn-normal" onclick="searchData();"><i class="layui-icon layui-icon-search"></i> 查询</button>
                </div>
            </div>

        </div>
    </form>
    <table class="layui-table" id="taskTable" lay-filter="taskTable"></table>

    <script>

        var taskId;//巡检任务编号,用户查看任务详情
        //全局定义一次, 加载formSelects
        layui.config({
            base: '${path}/layui/lay/modules/' //此处路径请自行处理, 可以使用绝对路径
        }).extend({
            formSelects: 'formSelects-v4.min'
        });


       function searchData(){
            layui.table.reload("taskTable",{
                page:{
                    curr : 1
                },
                where:{
                    "inspectionTaskCode":$("#taskId").val(),
                    "lineCode" : $("#lineCode").val(),
                    "issuedByName" : $("#issuedByName").val(),
                    "startTime" : $("#startTime").val(),
                    "endTime" : $("#endTime").val(),
                    "taskStateId" : $("#taskStateId").val()
                }
            });
        }


        layui.use(["table","form","formSelects","laydate"],function () {
            var table = layui.table;
            table.render({
                id:'taskTable',
                elem:'#taskTable',
                url:'/taskReturn/list',
                page:true,
                even:false,
                cols:[[
                    {field:'inspectionTaskCode', title:'任务编号'},
                    {field:'inspectionTaskName', title:'任务名称'},
                    {field:'lineName', title:'巡检线路'},
                    {field:'startPoleCode', title:'起始杆号'},
                    {field:'endPoleCode', title:'终止杆号'},
                    {field:'issuedByName', title:'下发人'},
                    {field:'issuedTime', title:'下发时间'},
                    {field:'taskStateName', title:'任务状态'},
                    {field:'taskStateId',title:'操作',width:'200',templet:function (d) {
                            var select = "blue";
                            var fenpei = "blue";
                            var update = "blue";
                            var del = "blue";
                            //行内工具栏
                            var fenpeiEvent = 'lay-event="huizhi"';
                            var updateEvent = 'lay-event="open"';
                            var delEvent = 'lay-event="edit"';
                            if(d.taskStateId == 4) {
                                fenpei = "#999999";
                                update = "#999999";
                                del = "#999999";
                                fenpeiEvent = "";
                                updateEvent = "";
                                delEvent = "";
                            }else if(d.taskStateId == 3){
                                update = "#999999";
                                fenpei = "#999999";
                                updateEvent = "";
                                fenpeiEvent = "";
                            }
                            var a = '<a href="javascript:void(0)" lay-event="selectTask"  style=color:'+select+'>查看</a> | ' +
                                '<a href="javascript:void(0)" '+fenpeiEvent+'  style=color:'+fenpei+'>回执录入</a> | ' +
                                '<a href="javascript:void(0)" '+updateEvent+' style=color:'+update+'>执行' +
                                '</a> | ' +
                                '<a href="javascript:void(0)" '+delEvent+' style=color:'+del+'>修改</a>';
                            return a;
                        }}
                ]]
            })



            //监听 行
            table.on("tool(taskTable)",function (obj) {
                var data = obj.data;
                if (obj.event == 'edit'){
                    window.open("/taskReturn/returnTaskView?taskId="+obj.data.id,"middle");
                }else if(obj.event == 'open'){
                    $.get("/task/open",{"taskId":obj.data.id},function (data) {
                        if(data){
                            layer.msg('开始执行!',{icon:1})
                            table.reload('taskTable');
                        }
                    })
                }else if(obj.event == 'huizhi'){
                    window.open("/taskReturn/returnTaskView?taskId="+obj.data.id,"middle");
                }else if(obj.event == 'selectTask'){
                    window.open("/task/InspectorDetialIndex?taskId="+obj.data.id,"middle");
                }
            })
        });

        layui.use('laydate',function () {
           var laydate = layui.laydate;

           laydate.render({
               elem:'#startTime'
           });
           laydate.render({
                elem:'#endTime'
           });
            laydate.render({
                elem: '#issuedTime'
                ,value: new Date()
                ,isInitValue: true
            });
        });

    </script>

</body>
</html>
